package com.example.product;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Product product1 = new Product("Coca Cola",3,1);
        final Product product2 = new Product("Pepsi Cola",5,2);
        final Product product3 = new Product("Mirinda     ",2,3);
        final Product product4 = new Product("Jasmine Tea",6,4);
        final Product product5 = new Product("Deluxe Milk",8,5);
        final Product product6 = new Product("Pocari Sweat",5,6);
//        final Product product7 = new Product("Coca Cola",7,7);
//        final Product product8 = new Product("Coca Cola",2,8);
        final EditText information_production = (EditText)findViewById(R.id.information_production);
        Button delete = (Button)findViewById(R.id.delete);
        Button Product = (Button)findViewById(R.id.Product);
        Button find = (Button)findViewById(R.id.find);
        Button sorting =(Button)findViewById(R.id.sorting);
        final LinkedUnorderedList linkedUnorderedList = new LinkedUnorderedList();
        linkedUnorderedList.addToFront(product2);
        linkedUnorderedList.addToRear(product1);

        linkedUnorderedList.addToRear(product4);
        linkedUnorderedList.addToRear(product6);
        linkedUnorderedList.addToRear(product3);
        linkedUnorderedList.addToRear(product5);

        Button insert = (Button)findViewById(R.id.insert);
        final Button loaded = (Button)findViewById(R.id.loaded);
        Product.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                information_production.setText("\t" + product1.toString() +"\t"+ product2.toString() +"\t"+ product3.toString()
                        +"\t"+ product4.toString()+"\t"+ product5.toString()+"\t"+ product6.toString()+"\t");
            }
        });
        loaded.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                information_production.setText(linkedUnorderedList.toString());
            }
        });
        find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String find = String.valueOf(linkedUnorderedList.find(product6));
                information_production.setText("          " +find);
            }
        });
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                linkedUnorderedList.remove(product6);
                information_production.setText(linkedUnorderedList.toString());
            }
        });
        insert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                linkedUnorderedList.addAfter(product6,product3);
                information_production.setText(linkedUnorderedList.toString());
            }
        });
        sorting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                linkedUnorderedList.Selection_Sorting(linkedUnorderedList);
                information_production.setText(linkedUnorderedList.toString());
            }
        });
    }
}
